package prototype.demo1;

/**
 * 原型模式
 */
public class Realizetype implements Cloneable {

    private String name;

    public String getName() {
        return name;
    }

    public Realizetype(String name) {
        System.out.println("有参构造 创建对象");
        this.name = name;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        System.out.println("clone() 方法调用，克隆新对象");
        return super.clone();
    }
}
class Test{
    public static void main(String[] args) throws CloneNotSupportedException {

        Realizetype realizetype = new Realizetype("xiangjiao");
        System.out.println("-->"+realizetype);

        Realizetype clone = (Realizetype) realizetype.clone();
        System.out.println("===>"+clone);
        System.out.println("===>"+clone.getName());

    }
}
